
#ifndef _FILEMAPPINGIMPL_H_
#define _FILEMAPPINGIMPL_H_

#include <cstdint>
#include <string>

#include <Windows.h>

#include "File.h"

class FileMappingImpl
{
public:
	FileMappingImpl();
	~FileMappingImpl();
public:
	bool Open(std::string const &strFileName, File::OpenMode eMode);
	bool Create(std::string const &strFileName, File::OpenMode eMode);
	bool IsOpen() const;
	void Close();
	bool IsEmpty() const;
	std::uint64_t Size() const;
public:
	void Read(void* lpData, int n);
	void Write(void* lpData, int n);
	void Append(void* lpData, int n);
	bool Seek(std::uint64_t nOffset, File::Pos ePos);
	// 	public:
	// 		std::uint8_t ReadUint8();
	// 		std::uint16_t ReadUint16();
	// 		std::uint32_t ReadUint32();
	// 		std::uint64_t ReadUint64();
	// 		std::int8_t ReadInt8();
	// 		std::int16_t ReadInt16();
	// 		std::int32_t ReadInt32();
	// 		std::int64_t ReadInt64();
	// 		float ReadFloat();
	// 		double ReadDouble();
private:
	bool Resize(int dSize);
private:
	void ParseErrorMessage();
	void ParsePara(File::OpenMode eMode);
private:
	HANDLE m_hFile;
	HANDLE m_hMapping;
	unsigned char* m_lpData;
	DWORD m_dwLocalOffset;
	std::string m_strErrorMessage;
	LARGE_INTEGER m_qwSize;
	LARGE_INTEGER m_qwCurrentOffset;
	DWORD m_dwCurrentSize;
	DWORD m_dwGranularity;
	DWORD m_para[4];

};


#endif



